/**
 * 
 */
package com.technodo.utils;

import java.util.Date;
import java.util.Random;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.technodo.R;


/**
 * @author Shantanu
 *
 */
public class GenericDialogActivity extends Dialog implements android.view.View.OnClickListener {

	private static final String TAG = "GenericDialogActivity";
	private Date dateToDisplay;
	private String heading;
	private String playerName;
	private String mainImagePath;
	private String smallImagePath;
	private String quote;
	private String quoter;
	private int soundId;
	private String[] autogeneratedText ={"Unvieled","Launched","Unleashed","Unreveled","Uncovered","Unrolled"};
	private static final String GET_PATH = "data/profiles/images/human.png";

	public GenericDialogActivity (Context context, String heading, String playerName, String mainImagePath, String quote, String quoter, int soundId) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		Date date = new Date();
		this.dateToDisplay = date;
		this.heading = heading;
		this.playerName = playerName;
		this.mainImagePath = GlobalPreferences.getGlobalPreferences().getDataDir() + mainImagePath;
		this.smallImagePath = GlobalPreferences.getGlobalPreferences().getDataDir()+GET_PATH;
		this.quote = quote;
		this.quoter = quoter;
		this.soundId = soundId;
		startGenericDialog();
	}

	public void startGenericDialog() {
		
		//to play the sound
		GlobalPreferences.playSound(getContext(), soundId);
		
//		Log.d(TAG, "in startGenericDialog()");

		Bitmap bitmap = null;

		setContentView(R.layout.generic_dialog);
		Random random = new Random();

		TextView showDateTextView =(TextView)findViewById(R.id.showDateView);
		showDateTextView.setText(dateToDisplay.toString());

		TextView leftHeadingTextView = (TextView)findViewById(R.id.leftView);
		leftHeadingTextView.setTypeface(null, Typeface.ITALIC);

		TextView dialogHeading = (TextView)findViewById(R.id.dialogHeadingView);
		dialogHeading.setText(heading);

		TextView playerNameTextView = (TextView)findViewById(R.id.playerTextView);
		playerNameTextView.setText(playerName);

		ImageView mainImageView = (ImageView)findViewById(R.id.mainImageView);
		bitmap = BitmapFactory.decodeFile(mainImagePath);
		mainImageView.setImageBitmap(bitmap);
		//mainImageView.setImageResource(R.drawable.person);

		ImageView smalImageView = (ImageView)this.findViewById(R.id.smallImageView);
		bitmap = BitmapFactory.decodeFile(smallImagePath);
		smalImageView.setImageBitmap(bitmap);
		//smalImageView.setImageResource(R.drawable.person1);

		TextView quoteTextView = (TextView)findViewById(R.id.quoteTextView);
		quoteTextView.setText(quote);

		TextView quoterTextView = (TextView)findViewById(R.id.quoterTextView);
		quoterTextView.setText(quoter);

		TextView playerChild2View = (TextView)findViewById(R.id.playerChild2TextView);
		playerChild2View.setText(heading);

		TextView randomTextView = (TextView)findViewById(R.id.randomTextView);
		randomTextView.setText(autogeneratedText[random.nextInt(autogeneratedText.length)]);

		Button okButton = (Button)findViewById(R.id.okButton);
		okButton.setText("OK");
		okButton.setOnClickListener(this);

//		Log.d(TAG, "in startGenericDialog() end");
	}

	public void onClick(View v) {
		GlobalPreferences.stopSound();
		Log.d(TAG, "inonClick");
		GlobalPreferences.playSound(getContext(), R.raw.turn_over);
		dismiss();
	} 
}

